home *** CD-ROM | disk | FTP | other *** search
/ Beginning Mac Programming / Beginning Mac Programming.bin / pc / Open Me for REALbasic 3 / REALbasic 3.2 / Goodies / 3rd Party Demos / 3rd Party Plugins / Multimedia / SGBplugs / BoilerPlatePlug.cpp next >
Encoding:
C/C++ Source or Header  |  1998-10-27  |  7.0 KB  |  251 lines

  1. #include "rb_plugin.h"
  2.  
  3. // An original (but useless) creation by:
  4. //      Shane Blackburn © 1998
  5.  
  6.  
  7. extern struct REALcontrol boilerplate_Control;
  8.  
  9. //*************************************
  10. //*         PROPERTIES STRUCT         *
  11. //*************************************
  12.  
  13. struct boilerplate_Data
  14. {
  15.     int backColour;
  16.     int rivetFace;
  17.     int rivetShadow;
  18.     int xRivets;
  19.     int yRivets;
  20.     int spacing;
  21.     int xMargin;
  22.     int yMargin;
  23.     int diam;
  24.     Boolean rivets;
  25.     Boolean outerFrame;
  26.     Boolean innerFrame;
  27. };
  28.  
  29. //*************************************
  30. //*          SUPPORT ROUTINES         *
  31. //*************************************
  32.  
  33. //----------------------------------------------------------------
  34.  
  35. RGBColor faceCol,shadowCol;
  36. int dx,dy;
  37.  
  38. //----------------------------------------------------------------
  39. int setRGB(int r,int g,int b)
  40. {
  41. return r*(256*256)+g*256+b;
  42. }
  43. //----------------------------------------------------------------
  44. RGBColor getRGB(int c)
  45. {
  46. RGBColor col;
  47.  
  48. col.red=(c >> 16) *257;
  49. col.green=((c >> 8) & 0xFF) *257;
  50. col.blue=(c & 0xFF) *257;
  51.  
  52. return col;
  53. }
  54. //----------------------------------------------------------------
  55. void drawRivet(int x,int y,int d,int xMargin,int yMargin)
  56. {
  57. Rect r;
  58.  
  59.     SetRect(&r,
  60.         x+xMargin/2-d/2+dx,y+yMargin/2-d/2+dy,
  61.         x+xMargin/2+(d-d/2)+dx,y+yMargin/2+(d-d/2)+dy);
  62.     RGBForeColor(&shadowCol);
  63.     PaintOval(&r);    
  64.     SetRect(&r,
  65.         x+xMargin/2-d/2,y+yMargin/2-d/2,
  66.         x+xMargin/2+(d-d/2),y+yMargin/2+(d-d/2));
  67.     RGBForeColor(&faceCol);
  68.     PaintOval(&r);
  69. }
  70. //----------------------------------------------------------------
  71.  
  72. //*************************************
  73. //*      METHODS IMPLEMENTATION       *
  74. //*************************************
  75.  
  76. //----------------------------------------------------------------
  77. static int boilerplate_xRivets(REALcontrolInstance instance)
  78. {
  79.     ControlData(boilerplate_Control, instance, boilerplate_Data, data);
  80.  
  81. return data->xRivets+1;
  82. }
  83. //----------------------------------------------------------------
  84. static int boilerplate_yRivets(REALcontrolInstance instance)
  85. {
  86.     ControlData(boilerplate_Control, instance, boilerplate_Data, data);
  87.  
  88. return data->yRivets+1;
  89. }
  90. //----------------------------------------------------------------
  91. static void boilerplate_Init(REALcontrolInstance instance)
  92. {
  93.     ControlData(boilerplate_Control, instance, boilerplate_Data, data);
  94. //default settings
  95.     data->diam=2;
  96.     data->xMargin=10;
  97.     data->yMargin=10;
  98.     data->spacing=30;
  99.     data->rivets=false;
  100.     data->innerFrame=false;
  101.     data->outerFrame=true;
  102.     data->backColour=setRGB(180,180,180);
  103.     data->rivetFace=setRGB(230,230,230);
  104.     data->rivetShadow=setRGB(128,128,128);
  105. }
  106. //----------------------------------------------------------------
  107. static void boilerplate_Paint(REALcontrolInstance instance)
  108. {
  109. Rect b;
  110. RGBColor fillCol,old;
  111. int i,width,height;
  112. float w,h,x,y;
  113.  
  114.     ControlData(boilerplate_Control, instance, boilerplate_Data, data);
  115.     REALGetControlBounds(instance, &b);
  116.  
  117.     GetForeColor(&old);
  118.  
  119.     if (data->rivets) 
  120.         {dx=1; dy=1;}
  121.         else
  122.         {dx=-1; dy=-1;}
  123.  
  124.     width=b.right-b.left- data->xMargin;
  125.     height=b.bottom-b.top- data->yMargin;
  126.     data->xRivets=width/ data->spacing; w=width/ data->xRivets;
  127.     data->yRivets=height/ data->spacing; h=height/ data->yRivets;
  128.  
  129.     fillCol=getRGB(data->backColour);
  130.     shadowCol=getRGB(data->rivetShadow);
  131.     faceCol=getRGB(data->rivetFace);
  132.     
  133.     RGBForeColor(&fillCol);
  134.     PaintRect(&b);
  135.  
  136.     x=b.left; y=b.top;
  137.     for (i=0;i<data->xRivets;i++)
  138.         {
  139.         drawRivet(x,b.top, data->diam, data->xMargin, data->yMargin);
  140.         drawRivet(x,b.bottom, data->diam, data->xMargin, -data->yMargin);
  141.         x=x+w;
  142.         }
  143.     
  144.     drawRivet(b.right,b.top, data->diam, -data->xMargin, data->yMargin);
  145.     drawRivet(b.right,b.bottom, data->diam, -data->xMargin, -data->yMargin);
  146.     
  147.     for (i=1;i< data->yRivets;i++)
  148.         {
  149.         y=y+h;
  150.         drawRivet(b.left,y, data->diam, data->xMargin, data->yMargin);
  151.         drawRivet(b.right,y, data->diam, -data->xMargin, data->yMargin);
  152.         }
  153.  
  154.     RGBForeColor(&shadowCol);
  155.  
  156. if (data->outerFrame) FrameRect(&b);
  157.  
  158. if (data->innerFrame)
  159.  {
  160.     InsetRect(&b,1,1);
  161.     width+=data->xMargin-2; height+=data->yMargin-2;
  162.     MoveTo(b.left+data->xMargin,b.top);     Line(0,height);
  163.     MoveTo(b.right-data->xMargin,b.top);    Line(0,height);
  164.     MoveTo(b.left,b.top+data->yMargin);     Line(width,0);
  165.     MoveTo(b.left,b.bottom-data->yMargin);  Line(width,0);
  166.  
  167.     RGBForeColor(&faceCol);
  168.     MoveTo(b.left+data->xMargin-dx,b.top);     Line(0,height);
  169.     MoveTo(b.right-data->xMargin-dx,b.top);    Line(0,height);
  170.     MoveTo(b.left,b.top+data->yMargin-dy);     Line(width,0);
  171.     MoveTo(b.left,b.bottom-data->yMargin-dy);  Line(width,0);
  172. }
  173.     RGBForeColor(&old);
  174. }
  175. //-------------------------------------------------------------
  176.  
  177. //*************************************
  178. //*            EXPORT TABLE           *
  179. //*************************************
  180. REALexport pluginExports[] = {
  181.     { nil, boilerplate_Init},
  182.     { nil, boilerplate_Paint},
  183.     { nil, boilerplate_xRivets},
  184.     { nil, boilerplate_yRivets},
  185. };
  186.  
  187. short pluginExportCode = sizeof(pluginExports) / sizeof(REALexport);
  188.  
  189.  
  190.  
  191. //*************************************
  192. //*         PLUGIN DEFINITION         *
  193. //*************************************
  194.  
  195. REALproperty boilerplate_Properties[] = {
  196.     { "Colouring", "FillColour", "Color", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, backColour) },
  197.     { "Colouring", "RivetFace", "Color", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, rivetFace) },
  198.     { "Colouring", "RivetShadow", "Color", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, rivetShadow) },
  199.     { "Appearance", "MinSpacing", "Integer", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, spacing) },
  200.     { "Appearance", "xMargin", "Integer", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, xMargin) },
  201.     { "Appearance", "yMargin", "Integer", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, yMargin) },
  202.     { "Appearance", "Diameter", "Integer", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, diam) },
  203.     { "Appearance", "Rivet", "Boolean", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, rivets) },
  204.     { "Appearance", "OuterFrame", "Boolean", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, outerFrame) },
  205.     { "Appearance", "InnerFrame", "Boolean", REALpropInvalidate, -2, -2, FieldOffset(boilerplate_Data, innerFrame) }
  206. };
  207.  
  208. //seem to need at least one event defined here,
  209. //so this is it...
  210. REALevent boilerplate_Events[] = {
  211.     {"Action" }
  212. };
  213.  
  214. //having no methods seems to cause a problem, so here are
  215. //some getter functions of dubious importance
  216. REALmethodDefinition boilerplate_Methods[] = {
  217.     {2,REALnoImplementation,"xRivets as integer"},
  218.     {3,REALnoImplementation,"yRivets as integer"},
  219. };
  220.  
  221. REALcontrolBehaviour boilerplate_Behaviour = {
  222.     &pluginExports[0],
  223.     nil,
  224.     &pluginExports[1],
  225.     nil,
  226.     nil,
  227.     nil,
  228. };
  229.  
  230. REALcontrol boilerplate_Control = {
  231.     kCurrentREALControlVersion,
  232.     "BoilerPlate",
  233.     sizeof(boilerplate_Data),
  234.     0,
  235.     169,
  236.     170,
  237.     64, 64,
  238.     boilerplate_Properties,
  239.     sizeof(boilerplate_Properties) / sizeof(REALproperty),
  240.     boilerplate_Methods,
  241.     sizeof(boilerplate_Methods) / sizeof(REALmethodDefinition),
  242.     boilerplate_Events,
  243.     sizeof(boilerplate_Events) / sizeof(REALevent),
  244.     &boilerplate_Behaviour
  245. };
  246.  
  247. void PluginEntry(void)
  248. {
  249.     REALRegisterControl(&boilerplate_Control);
  250. }
  251.